<template>
<!--  <wx-open-launch-weapp-->
<!--    id="launch-btn"-->
<!--    appid="wx12345678"-->
<!--    path="pages/home/index?user=123&action=abc"-->
<!--    v-if='defaultShowState'-->
<!--  >-->
<!--    <script type="text/wxtag-template">-->
<!--      <style>.btn { padding: 12px }</style>-->
<!--      <button class="btn">打开小程序</button>-->
<!--    </script>-->
<!--  </wx-open-launch-weapp>-->
</template>

<script setup lang='ts'>
import { onMounted,ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import {getAppByType} from '@/api/home'
const router = useRouter()
const route = useRoute()
let defaultShowState:boolean = false
onMounted(() =>{
  console.log('route:',route)
  if(route.query.link ==3){
    defaultShowState = true
  }else{

  getAppByTypes()
  }
  // handleDownLoad(route)
})
//按客户端类型获取最新地址
// async function getAppType() {
//   let res = await getAppByType({clientType:route.query.link})
//   console.log(res)
// }
function handleDownLoad(path) {
  const link = document.createElement('a');
  link.href = path; // 替换为实际的下载链接
  // link.download = '期望的文件名.文件扩展名'; // 替换为期望的文件名和扩展名
  link.download = ''; // 替换为期望的文件名和扩展名
  link.style.display = 'none'; // 设置为隐藏元素
  document.body.appendChild(link); // 将元素添加到body中
  link.click(); // 模拟点击以开始下载
  document.body.removeChild(link); // 下载完成后移除元素
}
async function getAppByTypes() {
  let res = await getAppByType({clientType:route.query.link})
  console.log(res)
  let {downloadUrl} = res.data
  handleDownLoad(downloadUrl)
}
</script>

<style scoped>

</style>